package com.woniuxy.bookmall.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.bookmall.entity.TBanner;
import com.woniuxy.bookmall.entity.TBooktype;
import com.woniuxy.bookmall.service.BannerService;
import com.woniuxy.bookmall.service.BookService;
import com.woniuxy.bookmall.service.BookTypeService;
import com.woniuxy.bookmall.vo.EsBook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@Controller
public class BookController {
    @Autowired
    BookService bookService ;
    @Autowired
    BookTypeService bookTypeService ;
    @Autowired
    BannerService bannerService ;
    /**
     *
     * @param id  图书类型id
     * @return
     */
    @RequestMapping("/book/showBook")
    public String showBook(@RequestParam(value = "now",defaultValue = "1") Integer now,
                           @RequestParam(value = "size",defaultValue = "10")Integer size ,
                           @RequestParam(value = "id",defaultValue = "0")int id,
                           Map map,String bname) {
        PageInfo<EsBook> pageInfo = bookService.findEsBookByBookType(id,bname, now, size);
        map.put("pageInfo", pageInfo);
        //1.查询  图书分类
        List<TBooktype> typeList = bookTypeService.findAll();
        //2.查询  轮播图
        List<TBanner> bannerList = bannerService.findAll();
        map.put("typeList", typeList);
        map.put("bannerList", bannerList);
        map.put("typeId",id);
        map.put("bname",bname);
        return "book";
    }

    @RequestMapping("/book/searchDetail")
    public String showBookDetail(Long id,Map map){
        EsBook esBook = bookService.findEsBookById(id);
        map.put("book",esBook);
        return "book-detail" ;
    }
}